package com.example.administrator.hqq.adapter.register;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.bean.MessageBean;
import com.example.administrator.hqq.utils.transform.GlideRoundTransform;
import com.zhy.autolayout.AutoRelativeLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2018/11/8 18:20
 * @remark:
 */
public class HobbiesAdapter extends BaseAdapter {
    private List<MessageBean.DataBean> list;
    private Context context;

    public HobbiesAdapter(Context hobbiesActivity, List<MessageBean.DataBean> data) {
        this.context = hobbiesActivity;
        this.list = data;
    }

    @Override
    public int getCount() {
        if (list.size() >= 0&&list.size()<12) {
            return list.size() + 1;
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.head_image_layout, viewGroup, false);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (i == list.size()) {
            viewHolder.autoAdd.setVisibility(View.GONE);
            viewHolder.more.setVisibility(View.VISIBLE);
            viewHolder.more.setImageResource(R.drawable.more);
        } else {
            viewHolder.solidCircle.setSelected(list.get(i).isSelect());
            viewHolder.title.setText(list.get(i).getName());
            viewHolder.autoAdd.setVisibility(View.VISIBLE);
            viewHolder.more.setVisibility(View.GONE);
            Glide.with(context).load(list.get(i).getUrl()).transform(new CenterCrop(context), new GlideRoundTransform(context, 5)).into(viewHolder.add);
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.add)
        ImageView add;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.solid_circle)
        AutoRelativeLayout solidCircle;
        @BindView(R.id.auto_add)
        AutoRelativeLayout autoAdd;
        @BindView(R.id.more)
        ImageView more;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
